<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/app.css" />
		<style>
			.link {
				margin-top: 10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content">
			<div style="padding: 10px;">
				<form class="mui-input-group">
					<div class="mui-input-row">
						<label>用户名</label>
						<input value="xjh" id="username" type="text" class="mui-input-clear" placeholder="请输入用户名">
					</div>
					<div class="mui-input-row">
						<label>密码</label>
						<input value="1234" id="password" type="password" class="mui-password" placeholder="请输入密码">
					</div>
				</form>

				<div class="link">
					<button id="lg" type="button" class="mui-btn mui-btn-red mui-btn-block">登录</button>
					<div style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
						<div>
							<input type="checkbox" name="" id="xy" />
							<span id="gb" style="font-size: 15px;">阅读隐私协议</span>
						</div>
						<a href="" id="rg" style="font-size: 14px;">暂无账户，点击注册</a>
					</div>
				</div>
			</div>
		</div>

		<script src="js/mui.min.js"></script>
		<script src="libs/app.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init()
			document.getElementById('lg').addEventListener('tap', function() {
				var xy = document.getElementById("xy")
				if (!xy.checked) {
					mui.confirm('是否勾选隐私协议', '提示', ['否', '是'], function(e) {
						console.log(e.index);
						if (e.index) {
							xy.checked = true
						} else {
							mui.openWindow('xy.html', 'xy.html', {})
						}
					}, 'div')
				} else {
					post('/api/user/login', {
						username: document.getElementById("username").value.trim(),
						password: document.getElementById("password").value.trim(),
					}).then(res => {
						console.log(res);
						mui.toast(res.msg)
						
						var data = res.data
						console.log(data);
						localStorage.setItem('token', data.userinfo.token)
						mui.openWindow('index.html', 'id', {})
					})
				}
			})
			document.getElementById('gb').addEventListener('tap', function() {
				mui.openWindow('xy.html', 'xy.html', {})
			})
			document.getElementById('rg').addEventListener('tap', function() {
				mui.openWindow('register.html', 'register.html', {})
			})
			window.addEventListener('ck',function(){
				document.getElementById("xy").checked = true
			})
		</script>
	</body>

</html>